home *** CD-ROM | disk | FTP | other *** search
- #ifndef __TEXTEDITCONTROL__
- #define __TEXTEDITCONTROL__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __TEXTSERVICES__
- #include <TextServices.h>
- #endif
-
- #ifndef __TSMTE__
- #include "TSMTE.h"
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- typedef Boolean (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, short *handled);
- /*
- ** ¶ Prototype for TextEditControl key filter function.
- **
- ** INPUT: teHndl TextEdit record that filter relates to.
- ** event Pointer to event record holding key event.
- ** OUTPUT: handled Pointer to short to hold action.
- ** RESULT: Boolean Return true if key should be filtered.
- **
- ** Each TextEdit control can have its own separate filter proc. Just call
- ** CTESetKeyFilter, and pass in the procPtr of your filter. If the character
- ** should be filtered, the filter should return true. If you do return true,
- ** then the value of “handled” is returned bt CTEKey.
- **
- ** Note that “handled” is initialized to 0, so you don’t have to set it unless
- ** the desired return value is other than 0.
- **
- ** __________
- **
- ** Also see: CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */
-
- typedef Boolean (*CTEFastKeysProcPtr)(TEHandle teHndl, EventRecord *event);
- /*
- ** ¶ Prototype for TextEditControl fast keys function.
- **
- ** INPUT: teHndl TextEdit record that fast keys proc relates to.
- ** event Pointer to event record holding key event.
- ** RESULT: Boolean Return true if key should be seen by application.
- **
- ** On slower Macs, going back to the main event loop for every character can
- ** adversely affect performance for TextEdit (and therefore the TextEdit control).
- ** By using a fast-keys filter, you can prevent looping back to the main event loop.
- ** The TextEdit control will loop itself, as long as there is a key in the
- ** event queue. Not all keys should be processed in fast-keys mode. That is
- ** the purpose of the filter. If the filter determines that the key is okay to
- ** be handled fast, it returns true. If the key should be handled by the
- ** application return false.
- **
- ** __________
- **
- ** Also see: CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */
-
- typedef struct CTEDataRec {
- short maxTextLen;
- Boolean newUndo;
- short undoSelStart;
- short undoSelEnd;
- Handle undoText;
- StScrpHandle undoStyl;
- short mode;
- Rect brdrRect;
- CTEKeyFilterProcPtr keyFilter;
- CTEFastKeysProcPtr fastKeys;
- TSMDocumentID docID;
- } CTEDataRec;
- typedef CTEDataRec *CTEDataPtr, **CTEDataHndl;
-
- pascal void ASMNOCARET(Rect *caretRect);
- pascal Boolean ASMTECLIKLOOP(void);
- /* Entry-points for the assembly glue. */
-
- void CTEActivate(Boolean active, TEHandle teHndl);
- /*
- ** ¶ Activate the indicated TextEdit record (and deactivate any other active one).
- **
- ** INPUT: active True to activate or false to deactivate.
- ** teHndl TextEdit record to activate (or deactivate).
- **
- ** Activate (or deactivate) this TextEdit record. If another is currently
- ** active, deactivate that one. The view control for this TextEdit record is
- ** also flagged to indicate which was the last active one for this window.
- ** If the previous active TextEdit record was in the same window, then flag
- ** the old one off for this window. The whole point for this per-window
- ** flagging is so that activate events can reactivate the correct TextEdit
- ** control per window.
- **
- ** __________
- **
- ** Also see: CTEFindActive, CTEWindActivate. */
-
- Boolean CTEClick(WindowPtr window, EventRecord *event, short *action);
- /*
- ** ¶ Handles a mouseDown in the content of a window.
- **
- ** INPUT: window Window click was made in.
- ** event Pointer to event record holding mouseDown event.
- ** OUTPUT: action Action taken by the TextEdit control.
- ** Pass in nil if you don’t care.
- ** RESULT: Boolean True if control used the event.
- **
- ** This is called when a mouseDown occurs in the content of a window. It
- ** returns true if the mouseDown caused a TextEdit action to occur. Events
- ** that are handled include if the user clicks on a scrollbar that is
- ** associated with a TextEdit control.
- **
- ** if CTEClick returns false, action is 0
- ** if CTEClick returns true, action is:
- ** -1 if control was activated by clicking on the TextEdit control or related scrollbar.
- ** 0 if control that was clicked on was already active.
- **
- ** __________
- **
- ** Also see: CTEEvent, CTEKey. */
-
- void CTEClikLoop(void);
- /*
- ** ¶ Utility function for TextEdit control.
- **
- ** This is the custom clikLoop, which is called from the assembly glue code.
- ** This handles updating the scrollbars as the user is drag-selecting in
- ** the TextEdit control. */
-
- ControlHandle CTEClipboard(short menuID);
- /*
- ** ¶ Handles cut-copy-paste-clear for the currently active TextEdit control.
- **
- ** INPUT: menuID 2 (cut), 3 (copy), 4 (paste), 5 (clear).
- ** RESULT: ControlHandle Control that took the menu event.
- **
- ** Do the cut-copy-paste-clear operations for the currently active
- ** TextEdit control. Caller assumes appropriateness of the call. Typically,
- ** this routine won’t be called at an inappropriate time, since the menu
- ** item should be enabled or disabled correctly.
- **
- ** Use CTEEditMenu to set the menu items undo-cut-copy-paste-clear correctly
- ** for the active TextEdit control. Since undo isn’t currently supported,
- ** all that CTEEditMenu does for the undo case is to deactivate it right now.
- ** If a TextEdit control content changes due to this operation, the control
- ** handle is returned.
- **
- ** __________
- **
- ** Also see: CTEConvertClipboard, CTEEditMenu. */
-
- void CTEConvertClipboard(Boolean convertClipboard, Boolean becomingActive);
- /*
- ** ¶ This is an empty function, used for backward-compatibility.
- **
- ** This used to be called to convert the clipboard. This task is now handled
- ** elsewhere, automatically. Calls to this function are obsolete, and can be
- ** removed.
- **
- ** __________
- **
- ** Also see: CTEClipboard, CTEEditMenu. */
-
- ControlHandle CTECtlHit(void);
- /*
- ** ¶ Returns the control that was hit (if any) by FindControl.
- **
- ** RESULT: ControlHandle Control that was hit.
- **
- ** The TextEdit control that was hit by calling FindControl is saved in a
- ** global variable, since the CDEF has no way of returning what kind it was.
- ** To determine that it was a TextEdit control that was hit, first call this
- ** function. The first call returns the old value in the global variable,
- ** plus it resets the global to nil. Then call FindControl, and then
- ** call this function again. If it returns nil, then a TextEdit control
- ** wasn’t hit. If it returns non-nil, then it was a TextEdit control that
- ** was hit, and specifically the one returned. */
-
- void CTEDispose(TEHandle teHndl);
- /*
- ** ¶ Disposes the TERecord, TextEdit control, and any related scrollbars.
- **
- ** INPUT: teHndl TextEdit handle (of the TextEdit control) to dispose.
- **
- ** Disposes of the TERecord, TextEdit control, and any related scrollbars.
- **
- ** __________
- **
- ** Also see: CTEDisposeView. */
-
- TEHandle CTEDisposeView(ControlHandle viewCtl);
- /*
- ** ¶ Dispose the view control and related scrollbars, but not the TERecord.
- **
- ** INPUT: viewCtl Control to dispose.
- ** RESULT: TEHandle Orphaned TextEdit record.
- **
- ** Dispose of the view control and related scrollbars. This function also
- ** returns the handle to the TextEdit record, since it was just orphaned.
- ** Use this function if you want to get rid of a TextEdit control, but you
- ** want to keep the TextEdit record.
- **
- ** __________
- **
- ** Also see: CTEDispose. */
-
- short CTEDocHeight(TEHandle teHndl);
- /*
- ** ¶ Returns the full document height.
- **
- ** INPUT: teHndl TextEdit record to get height for.
- ** RESULT: short Height of text in TextEdit record.
- **
- ** Returns the full TextEdit record text height.
- **
- ** __________
- **
- ** Also see: CTEGetLineHeight, CTEGetLineNum. */
-
- Boolean CTEEditMenu(Boolean *activeItem, short editMenu, short undoID, short cutID);
- /*
- ** ¶ Handle the enabling and disabling of the Edit menu, based on the active TextEdit control.
- **
- ** INPUT: editMenu ID of Edit menu to adjust.
- ** undoID ID of Edit menu item for undo item.
- ** cutID ID of Edit menu item for cut item.
- ** OUTPUT: activeItem Pointer to Boolean buffer. True is returned if there is an active item.
- ** Pass in nil if you don’t care.
- ** RESULT: Boolean True is returned if there is an active TextEdit record.
- **
- ** Enable or disable edit menu items based on the active TextEdit control.
- ** You pass the menu ID of the undo item in undoID, and the menu ID of the
- ** cut item in cutID. If undoID or cutID is non-zero, then some action is
- ** performed. If you pass a non-zero value for cutID, then the other menu
- ** items cut-copy-paste-clear are updated to reflect the status of the
- ** active TextEdit control.
- **
- ** __________
- **
- ** Also see: CTEClipboard, CTEConvertClipboard. */
-
- Boolean CTEEvent(WindowPtr window, EventRecord *event, short *action);
- /*
- ** ¶ Handle the event, either mouseDown or key event.
- **
- ** INPUT: window Window the event is for.
- ** event Pointer to the event record.
- ** OUTPUT: short Pointer to a short buffer to hold the returned action.
- ** Pass in nil if you don’t care.
- ** RESULT: Boolean True is returned if event is handled by a TextEdit control.
- **
- ** Handle the event if it applies to the active TextEdit control. If some
- ** action occured due to the event, return true.
- **
- ** if event not handled, false is returned and action is 0
- ** if event handled, true is returned and action is:
- ** -1: an inactive control was clicked on and it was made active.
- ** 0: an active control was clicked on and tracked.
- ** 1: the control took the keypress, but no change occured to the TERecord.
- ** 2: the control took the keypress and the TERecord changed.
- **
- ** __________
- **
- ** Also see: CTEClick, CTEKey. */
-
- TEHandle CTEFindActive(WindowPtr window);
- /*
- ** ¶ See if there is an active TextEdit control for this window.
- **
- ** INPUT: window Window to check for an active TextEdit control (or nil for all).
- ** RESULT: TEHandle The TEHandle of the active TextEdit control (or nil for none).
- **
- ** Returns the active TextEdit control, if any. If nil is passed in, then
- ** the return value represents whatever TextEdit control is active, independent
- ** of what window it is in. If a window is passed in, then it returns a
- ** TextEdit control only if the active control is in the specified window.
- ** If the active TextEdit control is in some other window, then nil is returned.
- **
- ** __________
- **
- ** Also see: CTEActivate, CTEWindActivate. */
-
-
- ControlHandle CTEFindCtl(WindowPtr window, EventRecord *event, TEHandle *teHndl,
- ControlHandle *ctlHit);
- /*
- ** ¶ See if a TextEdit control was clicked on directly.
- **
- ** INPUT: window Window to check for a clicked-on TextEdit control.
- ** event Pointer to the event record holding the mouseDown to check.
- ** OUTPUT: TEHandle The TEHandle of the clicked-on TextEdit control (or nil for none).
- ** Pass in nil if you don’t care.
- ** CtlHit The control clicked-on (or nil for none).
- ** Pass in nil if you don’t care.
- ** RESULT: ControlHandle The TextEdit control clicked-on (or nil for none).
- **
- ** This determines if a TextEdit control was clicked on directly. The control found
- ** and returned is the TextEdit control. The control hit may be the same, or it may be
- ** a related scrollbar. */
-
- TEHandle CTEFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
- /*
- ** ¶ Find the TextEdit record that is related to the indicated scrollbar.
- **
- ** INPUT: scrollCtl Window to check for a clicked-on TextEdit control.
- ** OUTPUT: retCtl The TextEdit control related to the scrollBar (or nil for none).
- ** Pass in nil if you don’t care.
- ** RESULT: TEHandle The TERecord clicked-on (or nil for none).
- **
- ** Find the TextEdit record that is related to the indicated scrollbar. */
-
- Rect CTEHide(TEHandle teHndl);
- /*
- ** ¶ Hide the designated TextEdit control and related scrollbars.
- **
- ** INPUT: teHndl TextEdit control to hide.
- ** Rect: Rect Bounding box of area affected by hide.
- **
- ** Hide the designated TextEdit control and related scrollbars. */
-
- void CTEIdle(void);
- /*
- ** ¶ Blink the caret in the active TextEdit control.
- **
- ** Blink the caret in the active TextEdit control. The active TextEdit
- ** control may be read-only, in which case the caret does not blink. */
-
- short CTEKey(WindowPtr window, EventRecord *event);
- /*
- ** ¶ Does keypress apply to TextEdit control? If so, handle it and return non-zero.
- **
- ** INPUT: window Window to check for active TextEdit control for key.
- ** event Pointer to event record holding keypress.
- ** RESULT: short Action taken by TextEdit control due to keypress.
- **
- ** See if the keypress event applies to the TextEdit control, and if it does,
- ** handle it and return non-zero.
- **
- ** if CTEKey returns 0, TextEdit control didn’t handle the event.
- ** if CTEKey returns 1, TextEdit control did handle the event, but the TERecord didn’t change.
- ** if CTEKey returns 2, TextEdit control did handle the event, and the TERecord changed. */
-
- void CTEMove(TEHandle teHndl, short newH, short newV);
- /*
- ** ¶ Move the designated TextEdit control and related scrollbars.
- **
- ** INPUT: teHndl TextEdit control to move.
- ** newH New horizontal location for TextEdit control.
- ** newV New vertical location for TextEdit control.
- **
- ** This function is used to move a TextEdit control. Pass it the TextEdit
- ** record to move, plus the new position. It will move the TextEdit control,
- ** along with any scrollbars the control may have. All areas that need
- ** updating are cleared and invalidated. */
-
- OSErr CTENew(short viewID, Boolean vis, WindowPtr window, TEHandle *teHndl, Rect *cRect,
- Rect *dRect, Rect *vRect, Rect *bRect, short maxTextLen, short mode);
-
- /*
- ** ¶ Create a new TextEdit control.
- **
- ** INPUT: viewID Resource number of the stub CDEF.
- ** vis Create control initially visible.
- ** window Create control into this window.
- ** cRect Pointer to rect for TextEdit control view rect.
- ** dRect Pointer to rect for TextEdit destRect.
- ** vRect Pointer to rect for TextEdit viewRect.
- ** bRect Pointer to rect for TextEdit control border rect.
- ** maxTextLen Maximum length allowed for TextEdit record.
- ** mode Choose various TextEdit control options.
- ** OUTPUT: teHndl Pointer to TEHandle to be created.
- ** Pass in nil if you don’t care.
- ** RETURN: OSErr Reason for control creation failure.
- **
- ** To create a TextEdit control, you only need a single call. For example:
- **
- ** mode = cteVScrollLessGrow; TERecord read-write, with vertical scroll
- ** that leaves space for grow box.
- **
- ** CTENew(rViewCtl, Resource ID of view control for TextEdit control.
- ** window, Window to hold TERecord.
- ** true, Initially visible.
- ** &teHndl, Return handle for TERecord.
- ** &ctlRect, Rect for TextEdit view control.
- ** &destRect, destRect for TERecord.
- ** &viewRect, viewRect for TERecord.
- ** &brdrRect, Used to frame a border.
- ** 32000, Max size for TERecord text.
- ** mode);
- **
- ** The various choices for the TextEdit control are defined as follows:
- **
- ** #define cteReadOnly 0x0001
- ** #define cteHScroll 0x0002
- ** #define cteHScrollLessGrow 0x0006
- ** #define cteVScroll 0x0008
- ** #define cteVScrollLessGrow 0x0018
- ** #define cteActive 0x0020
- ** #define cteNoBorder 0x0040
- ** #define cteShowActive 0x0080
- ** #define cteTabSelectAll 0x0100
- ** #define cteTwoStep 0x0200
- ** #define cteScrollFullLines 0x0400
- ** #define cteStyledTE 0x0800
- ** #define cteCenterJustify 0x1000
- ** #define cteRightJustify 0x2000
- ** #define cteNoFastKeys 0x4000
- **
- ** cteReadOnly: Don’t allow editing. When selected, don’t blink a caret.
- ** Allow text selection and copy-to-clipboard.
- ** cteHScroll: Create and manage a horizontal scrollbar for the TextEdit control.
- ** cteHScrollLessGrow: Create and manage a horizontal scrollbar for the TextEdit control,
- ** but leave space for a growIcon on the right end of the scrollbar.
- ** cteVScroll: Create and manage a vertical scrollbar for the TextEdit control.
- ** cteVScrollLessGrow: Create and manage a vertical scrollbar for the TextEdit control,
- ** but leave space for a growIcon on the bottom end of the scrollbar.
- ** cteActive: Make this the initially active control for the window.
- ** cteNoBorder: By default, you get a border around the TextEdit control. To turn this
- ** off, set this bit.
- ** cteShowActive: When the control is active, show that it is by drawing a selection
- ** border around the control. This is the new 7.0 human-interface
- ** method of showing which control is active. (This can be an important
- ** indicator because if you have readOnly TextEdit controls, they don’t
- ** have a blinking caret. If they also don’t have any text selected,
- ** there will be no indication that it is the active control.
- ** cteTabSelectAll: When using IsCtlEvent (discussed under "! using CtlHandler.c"),
- ** tab changes the active TextEdit (or List) control. When a TextEdit
- ** control is made active, sometimes it is desirable to initially select
- ** all of the text for the user. Setting this bit accomplishes this.
- ** cteTwoStep: When using IsCtlEvent, you may want the initial click on a TextEdit
- ** control to just select the control, or you may wish the click to start
- ** tracking in addition to selecting the control. The tracking is
- ** considered the second step, so by setting this bit, you will get
- ** tracking of the control on the initial click.
- ** cteScrollFullLines: This does as it sounds, but only if the TextEdit control isn’t styled.
- ** cteStyledTE: If you don’t need styles for this TextEdit control, leave this bit off.
- ** cteCenterJustify: As it sounds.
- ** cteRightJustify: As it sounds.
- ** cteNoFastKeys: The fast-keys feature allows the TextEdit control to check the OSEvent
- ** queue to see if there is another key event. If there is, it will
- ** handle it before returning control to the application. This local
- ** event processing allows a great speed increase in TextEdit performance,
- ** especially on slower Macs. Some applications will want to inhibit
- ** this behavior. Set this bit if you do.
- **
- ** Simply initialize ctlRect, destRect, viewRect, and brdrRect appropriately, and
- ** then call CTENew (which stands for Control TENew). If teHndl is returned
- ** nil, then CTENew failed. Otherwise, you now have a TextEdit control in the
- ** window. If it fails, it also returns an error stating why it failed
- ** (memFullErr or resNotFound).
- **
- ** NOTE: There is a TextEdit bug (no way!!) such that you may need to set the
- ** viewRect right edge 2 bigger than the right edge of destRect. If you
- ** do not do this, then there will be some clipping on the right edge in
- ** some cases. Of course, you may want this. You may want horizontal
- ** scrolling, and therefore you would want the destRect substantially
- ** larger than the viewRect. If you don’t want horizontal scrolling,
- ** then you probably don’t want any clipping horizontally, and therefore
- ** you will need to set destRect.right 2 less than viewRect.right.
- **
- **
- ** If the CTENew call succeeds, you then have a TextEdit control in your
- ** window. It will be automatically disposed of when you close the window.
- ** If you don’t waht this to happen, then you can detach it from the
- ** view control which owns it. To do this, you would to the following:
- **
- ** viewCtl = CTEViewFromTE(theTextEditHndl);
- ** if (viewCtl) SetCRefCon(viewCtl, nil);
- **
- ** The view control keeps a reference to the TERecord in the refCon.
- ** If the refCon is cleared, then the view control does nothing. So, all that
- ** is needed to detach a TERecord from a view control is to set the
- ** view control’s refCon nil. Now if you close the window, you will still
- ** have the TERecord.
- **
- **
- ** To remove a TextEdit control completely from a window, you make one call:
- **
- ** CTEDispose(theTextEditHndl);
- **
- ** This disposes of the TERecord, the view control, and any scrollbar
- ** controls that were created when the TextEdit control was created with
- ** the call CTENew.
- **
- **
- ** Events for TERecord are handled nearly automatically. You can
- ** make one of 3 calls:
- **
- ** CTEClick(window, eventPtr, &action);
- ** CTEEvent(window, eventPtr, &action);
- ** CTEKey(window, eventPtr);
- **
- ** In each case, if the event was handled, non-zero is returned. CTEEvent simply
- ** calls either CTEClick or CTEKey, whichever is appropriate.
- **
- ** Another call you will want to use is CTEEditMenu. This is used to set the
- ** state of cut/copy/paste/clear for TextEdit controls. It checks the active
- ** control to see if text is selected, if the control is read-only, etc.
- ** Based on this information, it sets cut/copy/paste/clear either active
- ** or inactive. If any menu items are set active, it returns true.
- **
- **
- ** One more high-level call is CTEUndo. In response to an undo menu item
- ** being selected by the user, just call CTEUndo, and the edits the user
- ** has made will be undone. (This includes undoing an undo.)
- **
- **
- ** The last high-level call for managing the edit menu is CTEClipboard. Call it
- ** when you want to do a cut/copy/paste/clear for the active TextEdit control.
- ** The value to pass is as follows:
- **
- ** 2: cut
- ** 3: copy
- ** 4: paste
- ** 5: clear
- **
- ** These are the same values you would pass to a DA for these actions. */
-
- void CTENewUndo(ControlHandle viewCtl, Boolean alwaysNewUndo);
- /*
- ** ¶ Register a new undo for the next TextEdit control editing operation.
- **
- ** INPUT: viewCtl Control to set a new undo for.
- ** alwaysNewUndo True if undo should be forced. (Not the case for normal typing.)
- **
- ** Save the data (if appropriate) so that user can undo. */
-
- ControlHandle CTENext(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
- /*
- ** ¶ Interate to the next TextEdit control.
- **
- ** INPUT: window Window whose control list is iterated.
- ** ctl Last control. Find next. (Use nil to start at beginning of list.)
- ** dir 1, walk control list forward. -1, walk control list backward.
- ** justActive True is just active (visible, hilite != -1).
- ** OUTPUT: teHndl Pointer to next TEHandle in list, based on criteria.
- ** Pass in nil if you don’t care.
- ** RETURN: ControlHandle Next control in list, based on criteria.
- **
- ** Get the next TextEdit control in the window. You pass it a control handle
- ** for the view control, or nil to start at the beginning of the list.
- ** It returns both a TextEdit handle and the view control handle for that
- ** TextEdit record. If none is found, nil is returned. This allows you to
- ** repeatedly call this function and walk through all the TextEdit controls
- ** in a window. */
-
- short CTENumTextLines(TEHandle teHndl);
- /*
- ** ¶ Get correct number of line in the TextEdit handle.
- **
- ** INPUT: teHndl TextEdit handle to count lines on.
- ** RETURN: short Number of lines in TextEdit handle.
- **
- ** Return the number of lines of text. This is because there is a bug in
- ** TextEdit where the number of lines returned is incorrect if the text
- ** ends with a c/r. This function adjusts for this bug. */
-
- OSErr CTEPrint(TEHandle teHndl, short *offset, Rect *rct);
- /*
- ** ¶ Get correct number of line in the TextEdit handle.
- **
- ** INPUT: teHndl TextEdit handle to print.
- ** IN/OUT offset Pointer to short holding offset to continue printing from.
- ** Rect Pointer to rect that text is wrapped in, and wrapped text
- ** boundary is returned in.
- ** RETURN: OSErr Some kind of error prevented completion (likely memFullErr).
- **
- ** Use this function to print the contents of a TextEdit record. Pass it a
- ** TextEdit handle, a pointer to a text offset, and a pointer to a rect to
- ** print the text in. The offset should be initialized to what character
- ** in the TextEdit record you wish to start printing at (most likely 0).
- ** The print function prints as much text as will fit in the rect, and
- ** then updates the offset to tell you what is the first character that didn’t
- ** print. You can then call the print function again with another rect with
- ** this new offset, and it will print the text starting at the new offset.
- ** This method is very useful when a single TextEdit record is longer than a
- ** single page, and you wish the text to break at the end of the page.
- ** The bottom of rect is also updated, along with the offset. The bottom edge
- ** of the rect is changed to reflect the actual bottom of the text printed.
- ** This is useful because the rect passed in didn’t necessarily hold an
- ** integer number of lines of text. The bottom of the rect is adjusted so
- ** it exactly holds complete lines of text.
- ** It is also possible that the rect could hold substantially more lines of
- ** text than there are remaining. Again, in this situation, the bottom of
- ** rect is adjusted so that the rect tightly bounds the text printed.
- ** The remaining piece of information passed back is an indicator that the
- ** text through the end of the TextEdit record was printed. When the end
- ** of the text is reached, the offset for the next text to be printed is
- ** returned as -1. This indicates that processing of the TextEdit record
- ** is complete. */
-
- Boolean CTEReadOnly(TEHandle teHndl);
- /*
- ** ¶ Return if the TextEdit control is read-write (true) or read-only (false).
- **
- ** INPUT: teHndl TextEdit handle in question.
- ** RETURN: Boolean read-write (true) or read-only (false).
- **
- ** Return if the TextEdit control is read-write (true) or read-only (false). */
-
- ControlHandle CTEScrollFromTE(TEHandle teHndl, Boolean vertScroll);
- /*
- ** ¶ Return control handle of scrollbar related to the TextEdit record.
- **
- ** INPUT: teHndl TextEdit handle in question.
- ** RETURN: Boolean read-write (true) or read-only (false).
- **
- ** Return the control handle for the TextEdit control’s scrollbar, either
- ** vertical or horizontal. If the scrollbar doesn’t, nil is returned. */
-
- ControlHandle CTEScrollFromView(ControlHandle viewCtl, Boolean vertScroll);
- /*
- ** ¶ Return control handle of scrollbar related to the TextEdit control.
- **
- ** INPUT: viewCtl TextEdit control in question.
- ** RETURN: Boolean read-write (true) or read-only (false).
- **
- ** Return the control handle for the scrollbar related to the view control,
- ** either horizontal or vertical. If the scrollbar doesn’t exist, return nil. */
-
- void CTESetKeyFilter(TEHandle teHndl, CTEKeyFilterProcPtr proc);
- /*
- ** ¶ Set TextEdit handle to be filtered.
- **
- ** INPUT: teHndl TextEdit handle to be filtered.
- ** proc Filter procedure for TextEdit handle.
- **
- ** A TextEdit control can have an optional key filter, which is called whenever
- ** CTEKey is called. If you pass in nil, then the filtering is turned off.
- ** This allows individual TextEdit controls to handle their own filtering.
- ** The filter procedure is of the form:
- ** Boolean (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, Boolean *handled);
- ** If true is returned, then CTEKey is aborted, and the value in "handled" is
- ** returned. By having a separate abort value and return value, you can determine
- ** if processing of the event should be continued or not, independent of whether
- ** or not you aborted CTEKey. */
-
- void CTESetFastKeys(TEHandle teHndl, CTEFastKeysProcPtr proc);
- /*
- ** ¶ Set TextEdit handle to accept keys "fast", i.e., in a local loop.
- **
- ** INPUT: teHndl TextEdit handle to be filtered.
- ** proc Fast-keys procedure.
- **
- ** Set your own fast-keys procedure. The fast-keys procedure returns whether or not
- ** the particular keypress can be handled without returning to the application.
- ** If the key can be handled as a fast key, then the proc should return true. */
-
- void CTESetSelect(short start, short end, TEHandle teHndl);
- /*
- ** ¶ Set a range of text. Use this instead of TESetSelect.
- **
- ** INPUT: start Offset of first char to be included in the selection range.
- ** stop Offset past last character to be included in the selection range.
- ** teHndl TextEdit handle to receive selection range.
- **
- ** Select a range of text. TESetSelect can’t be used alone because it doesn’t
- ** update the scrollbars. This function calls TESetSelect, and then fixes up
- ** the scrollbars. */
-
- void CTEShow(TEHandle teHndl);
- /*
- ** ¶ Unhide a hidden TextEdit control.
- **
- ** INPUT: teHndl TextEdit handle to unhide.
- **
- ** Show the designated TextEdit control and related scrollbars. */
-
- void CTESize(TEHandle teHndl, short newH, short newV, Boolean newDest);
- /*
- ** ¶ Change the size of a TextEdit control and related scrollbars.
- **
- ** INPUT: teHndl TextEdit handle to resize.
- ** newH New horizontal size.
- ** newV New vertical size.
- ** newDest Resize the destRect, along with other changes.
- **
- ** This function is used to resize a TextEdit control. Pass it the TextEdit
- ** record to resize, plus the new horizontal and vertical size. It will
- ** resize the TextEdit control, realign the text, if necessary, plus it will
- ** resize and adjust any scrollbars the TextEdit control may have. All areas
- ** that need updating are cleared and invalidated. */
-
- Handle CTESwapText(TEHandle teHndl, Handle newText, StScrpHandle styl, Boolean update);
- /*
- ** ¶ Change the size of a TextEdit control and related scrollbars.
- **
- ** INPUT: teHndl TextEdit handle to accept text.
- ** newText Handle of new text for TextEdit control.
- ** styl Optional style record (nil if none).
- ** update True if new text should be drawn after being accepted.
- **
- ** Swap the TextEdit text handle with the text handle passed in. If a non-nil styl
- ** value is passed in, apply the style scrap to the new text. A typical usage
- ** might look like:
- **
- ** DisposeHandle(CTESwapText(teHndl, textHndl, stylHndl, false));
- **
- ** CTESwapText returns the old handle, which is then disposed of, since it is
- ** typically no longer needed. */
-
-
- WindowPtr CTETargetInfo(TEHandle *teHndl, Rect *teView);
- /*
- ** ¶ Get information about the target TextEdit control.
- **
- ** OUTPUT: teHndl Active TextEdit handle (nil if none).
- ** Pass in nil if you don’t care.
- ** teView Bounding viewRct of activeTextEdit handle.
- ** Pass in nil if you don’t care.
- ** RESULT: WindowPtr Window containing active TextEdit control.
- **
- ** Return information for the currently active TextEdit control. The currently
- ** active TextEdit control is stored in gActiveTEHndl, and can be accessed
- ** directly. If gActiveTEHndl is nil, then there is no currently active one.
- ** The information that we return is the viewRect and window of the active
- ** TextEdit control. This is information that could be gotten directly, but
- ** this call makes it a little more convenient. */
-
- ControlHandle CTEUndo(void);
- /*
- ** ¶ Perform an undo function for the TextEdit control.
- **
- ** Perform an undo function for the TextEdit control.
- ** If a TextEdit control content changes due to this operation, the control
- ** handle is returned. */
-
- void CTEUpdate(TEHandle teHndl, ControlHandle ctl, Boolean justShowActive);
- /*
- ** ¶ Draw the TextEdit control and frame.
- **
- ** INPUT: teHndl TextEdit handle to draw.
- ** ctl TextEdit control to draw.
- ** justShowActive Just draw the active indicator, if any.
- **
- ** Draw the TextEdit control and frame, or possibly just the frame. */
-
- ControlHandle CTEViewFromTE(TEHandle teHndl);
- /*
- ** ¶ Get the control handle, give the TextEdit record.
- **
- ** INPUT: teHndl TextEdit handle to convert to control.
- **
- ** Return the control handle for the view control that owns the TextEdit
- ** record. Use this to find the view to do customizations such as changing
- ** the update procedure for this TextEdit control. */
-
- TEHandle CTEWindActivate(WindowPtr window, Boolean displayIt);
- /*
- ** ¶ Activate the TextEdit control for the activating window.
- **
- ** INPUT: window Window that was activated.
- ** displayIt Display the activation differences.
- ** RETURN: TEHandle The activated TextEdit handle (or nil for none).
- **
- ** Call this when a window with TextEdit controls is being activated. This
- ** will make the TextEdit control that was last active in this window the
- ** active TextEdit control again. */
-
- void CTEAdjustTEBottom(TEHandle teHndl);
- /*
- ** ¶ Adjust the bottom of the TextEdit record to remove extra white space.
- **
- ** INPUT: teHndl TextEdit record to adjust.
- **
- ** This function is called after an edit to make sure that there is no extra
- ** white space at the bottom of the viewRect. If there are blank lines at
- ** the bottom of the viewRect, and there is text scrolled off the top of the
- ** viewRect, then the TextEdit control is scrolled to fill this space, or as
- ** much of it as possible. */
-
- void CTEAdjustScrollValues(TEHandle teHndl);
- /*
- ** ¶ Adjust the scrollbar values to the TextEdit length and scroll position.
- **
- ** INPUT: teHndl TextEdit record whose scrollbars are to be adjusted.
- **
- ** Bring the scrollbar values up to date with the current document position
- ** and length. */
-
- StScrpHandle CTEGetFullStylScrap(TEHandle teHndl);
- /*
- ** ¶ Get the style scrap for the entire TextEdit control.
- **
- ** INPUT: teHndl TextEdit record to get scrap for.
- **
- ** This function gets the style scrap for the entire TextEdit control. It doesn’t
- ** matter what the current selection range is. The TextEdit control is left unaffected. */
-
- void CTESetStylScrap(short begRng, short endRng, StScrpHandle styles, TEHandle teHndl);
- /*
- ** ¶ Apply the style scrap to the TextEdit record.
- **
- ** INPUT: begRng Beginning of range (inclusive) to apply style to.
- ** endRng End of range (exclusive) to apply style to.
- ** styles Scrap syyles to apply.
- ** teHndl TextEdit record to apply styles to.
- **
- ** This function applies the style scrap to the TextEdit record. This function works better
- ** than the toolbox function TESetStylScrap. */
-
- short CTEGetLineNum(TEHandle te, short offset);
- /*
- ** ¶ Return the line number associated with the offset passed in.
- **
- ** INPUT: te TextEdit handle to get the line number for.
- ** offset Offset to find the line number for.
- **
- ** This function returns the line number associated with the offset passed in. */
-
- short CTEGetLineHeight(TEHandle te, short lineNum, short *ascent);
- /*
- ** ¶ Return the line height of the requested line number.
- **
- ** INPUT: te TextEdit handle to get the line number for.
- ** lineNum Line number to get height for.
- ** OUTPUT: ascent Ascent of line lineNum.
- ** Pass in nil if you don’t care.
- ** RESULT: short Line height of line lineNum.
- **
- ** This function returns the line height of the requested line number. */
-
- void CTEGetPStr(ControlHandle ctl, StringPtr pstr);
- /*
- ** ¶ Return the TextEdit control text as a pascal string.
- **
- ** INPUT: ctl TextEdit control to get pascal string for.
- ** OUTPUT: pstr Pascal string pointer to receive text.
- **
- ** This function returns the TextEdit control text as a pascal string. The maximum text
- ** returned is 255 chars. */
-
- void CTEPutPStr(ControlHandle ctl, StringPtr pstr);
- /*
- ** ¶ Set the TextEdit control text to a pascal string.
- **
- ** INPUT: ctl TextEdit control to get pascal string for.
- ** pstr Pascal string pointer that holds new TextEdit control text.
- **
- ** This function sets the TextEdit control text to the pascal string. */
-
- void CTESetPStr(ControlHandle ctl, StringPtr pstr);
- /*
- ** ¶ Set the TextEdit control text to a pascal string.
- **
- ** INPUT: ctl TextEdit control to get pascal string for.
- ** pstr Pascal string pointer that holds new TextEdit control text.
- **
- ** This function sets the TextEdit control text to the pascal string. */
-
- Boolean CTEUseTSMTE(void);
- /*
- ** ¶ Set the TextEdit control to use TSMTE.
- **
- ** OUTPUT: Boolean Returns true if can use TSMTE.
- **
- ** Call this function if you want the TextEdit control to use TSMTE. You still need to
- ** register and unregister your application with the TextServices Manager. That isn’t
- ** handled for you. AppWannabe’s Start.c file shows how this is done:
- **
- ** if(CTEUseTSMTE())
- ** InitTSMAwareApplication();
- **
- ** ... do app things here ...
- **
- ** if(CTEUseTSMTE())
- ** CloseTSMAwareApplication();
- **
- ** ExitToShell();
- */
-
- Boolean TSMTEAvailable(void);
- /*
- ** ¶ Check if TextServices init TSMTE is available.
- **
- ** OUTPUT: Boolean Returns true if TSMTE is available.
- **
- ** This function says if the TextServices init TSMTE is available for inline-input for
- ** TextEdit. Note that you should do the following at startup:
- **
- ** if(TSMTEAvailable())
- ** InitTSMAwareApplication();
- **
- ** And at application shutdown, you should do the following:
- **
- ** if(TSMTEAvailable())
- ** CloseTSMAwareApplication();
- */
-
- Boolean IsTECtl(ControlHandle ctl);
- /*
- ** ¶ Check if the control is a TextEdit control.
- **
- ** INPUT: ctl Handle of control to test to see if it is a TextEdit control.
- ** RESULT: Boolean True if control is a TextEdit control.
- **
- ** Check to see if the control is a TextEdit control. */
-
-
-
- typedef void (*CTEActivateProcPtr)(Boolean active, TEHandle teHndl);
- typedef Boolean (*CTEClickProcPtr)(WindowPtr window, EventRecord *event, short *action);
- typedef ControlHandle (*CTECtlHitProcPtr)(void);
- typedef TEHandle (*CTEFindActiveProcPtr)(WindowPtr window);
- typedef short (*CTEKeyProcPtr)(WindowPtr window, EventRecord *event);
- typedef ControlHandle (*CTENextProcPtr)(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
- typedef void (*CTESetSelectProcPtr)(short start, short end, TEHandle teHndl);
- typedef ControlHandle (*CTEViewFromTEProcPtr)(TEHandle teHndl);
- typedef TEHandle (*CTEWindActivateProcPtr)(WindowPtr window, Boolean displayIt);
-
- #define rTECtl 4000
-
- #define cteReadOnly 0x0001
- #define cteHScroll 0x0002
- #define cteHScrollLessGrow 0x0006
- #define cteVScroll 0x0008
- #define cteVScrollLessGrow 0x0018
- #define cteActive 0x0020
- #define cteNoBorder 0x0040
- #define cteShowActive 0x0080
- #define cteTabSelectAll 0x0100
- #define cteTwoStep 0x0200
- #define cteScrollFullLines 0x0400
- #define cteStyledTE 0x0800
- #define cteCenterJustify 0x1000
- #define cteRightJustify 0x2000
- #define cteNoFastKeys 0x4000
- #define cteTSMTE 0x8000
-
- #endif
-